package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.WitbigMapper;
import com.zygh.policeasset.pojo.Witbig;
import com.zygh.policeasset.service.WitbigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/witbig"})
@Api(tags = {"资产大类管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/WitbigController.class */
public class WitbigController {
    @Autowired
    WitbigService witbigService;
    @Autowired
    WitbigMapper witbigMapper;

    @RequestMapping(value = {"/findall"}, method = {RequestMethod.GET})
    @ApiOperation("获取全部资产大类列表")
    public Object findAll(@RequestParam(value = "type", required = false) String type) {
        return this.witbigService.findAll(type);
    }

    @RequestMapping(value = {"/listfindall"}, method = {RequestMethod.GET})
    @ApiOperation("获取全部资产大类分页列表")
    public Object getAllByRoot(@RequestParam("type") String type, @RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize) {
        return this.witbigService.listFindAll(type, pageNum, pageSize);
    }

    @RequestMapping(value = {"/findById"}, method = {RequestMethod.GET})
    @ApiOperation("根据ID查询")
    public Object findById(@RequestParam("id") Integer id) {
        return this.witbigService.findById(id);
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加资产大类")
    public Object add(@RequestBody Witbig params) {
        if (StrUtil.isEmpty(params.getWitbigName())) {
            return new CommonResult().validateFailed("名称不能为空");
        }
        if (this.witbigMapper.findCount(params.getType(), params.getWitbigName()).intValue() > 0) {
            return new CommonResult().validateFailed("资产大类名称已存在，请核对");
        }
        if (this.witbigService.add(params).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加错误");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改资产大类")
    public Object update(@RequestBody Witbig params) {
        if (StrUtil.isEmpty(params.getWitbigName())) {
            return new CommonResult().validateFailed("名称不能为空");
        }
        if (this.witbigMapper.findCount(params.getType(), params.getWitbigName()).intValue() > 0) {
            return new CommonResult().validateFailed("资产大类名称已存在，请核对");
        }
        if (this.witbigService.update(params).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改错误");
    }

    @RequestMapping(value = {"/remove"}, method = {RequestMethod.GET})
    @ApiOperation("删除资产大类")
    public Object remove(@RequestParam int id) {
        if (StrUtil.isEmpty(String.valueOf(id))) {
            return new CommonResult().validateFailed("id不能为空");
        }
        if (this.witbigService.remove(id).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除错误");
    }
}